#pragma once
#include <QPushButton>
#include <QWidget>

#include "widgets.h"
class SImage;
class S_WIDGETS_EXPORT SImageButton : public QWidget {
  enum class ImgType { kNormal, kHover, kPressed, kDisabled };
  Q_OBJECT
 public:
  SImageButton(QWidget* parent = nullptr, QString imageId = "",
               QString objectName = "", QString iconText = "");
  ~SImageButton() = default;

  void mousePressEvent(QMouseEvent* event);
  void mouseReleaseEvent(QMouseEvent* event);
  void enterEvent(QEvent* event);
  void leaveEvent(QEvent* event);
  void paintEvent(QPaintEvent* event);

  QSize sizeHint() const override;
  void setImg(SImage* img, ImgType type);  // TODO: shared_ptr to hold img?
  void setImgId(QString imageId);
  void setImgAlign(int align) { m_imgAlign = align; }
  void setIconText(const QString& text);
  int getIconTextLength();

  int index() const { return m_index; }
  void setIndex(int val) { m_index = val; }
  void setColor(QColor clrNormal, QColor clrHover, QColor clrPressed,
                QColor clrDisabled);
  void setTopOffset(int offset);

 signals:
  void clicked(int);
  void enterOrLeaved(bool);

 private:
  enum MouseState {
    normal = 0,
    hover,
    pressed,
  };
  SImage* m_imgNormal = nullptr;
  SImage* m_imgHover = nullptr;
  SImage* m_imgPressed = nullptr;
  SImage* m_imgDisabled = nullptr;
  SImage* m_curImg = nullptr;
  int m_index = 0;
  int m_topOffset = 0;
  int m_imgAlign = Qt::AlignRight;

  MouseState m_mouseState;
  bool m_useBgkColor;
  QColor m_clrNormal;
  QColor m_clrHover;
  QColor m_clrPressed;
  QColor m_clrDisabled;

  QString m_strIconText;
};
